<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>mouse</title>
    <style>
        img{
            width: 300px;
            height: auto
        ;
            background-color: hotpink;
            position: absolute;
            left: 0;
            top:0;
        }
    </style>
</head>
<body>
<h1>鼠标绑定小盒子</h1>
<img src="img/girl.jpg">

<script>
    //https://blog.csdn.net/fighting_no1/article/details/79314028?utm_medium=distribute.pc_relevant.none-task-blog-title-8&spm=1001.2101.3001.4242
let div=document.getElementsByTagName('img')[0]
    document.onmousemove=function (event) {
      let e=event||window.event; //浏览器兼容性问题
      // let e=window.event;
      div.style.left=e.clientX-div.clientWidth/2+'px'
      div.style.top=e.clientY-div.clientHeight/2+'px'
    }
</script>
</body>
</html>